package sdk.webview.fmc.com.fmcsdk.check.adapter;


import static android.content.Context.INPUT_METHOD_SERVICE;
import static sdk.webview.fmc.com.fmcsdk.util.ImageUtils.getDisplayMetrics;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.preference.PreferenceManager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.Layout;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.donkingliang.imageselector.utils.StringUtils;
import com.google.gson.Gson;

import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

import sdk.webview.fmc.com.fmcsdk.R;
import sdk.webview.fmc.com.fmcsdk.app.FMCApplication;
import sdk.webview.fmc.com.fmcsdk.bean.DDTypeBean;
import sdk.webview.fmc.com.fmcsdk.check.CacheHelper;
import sdk.webview.fmc.com.fmcsdk.check.TextViewSpanUtil;
import sdk.webview.fmc.com.fmcsdk.check.bean.GetDetailsBean;
import sdk.webview.fmc.com.fmcsdk.check.bean.ImageSelectBean;
import sdk.webview.fmc.com.fmcsdk.check.bean.StartEmptyEvent;
import sdk.webview.fmc.com.fmcsdk.check.dialog.BottomPopupWindow;
import sdk.webview.fmc.com.fmcsdk.check.dialog.CenterPopupWindow;
import sdk.webview.fmc.com.fmcsdk.check.listener.OnCameraPhotoListener;
import sdk.webview.fmc.com.fmcsdk.imagepicker.utils.Utils;
import sdk.webview.fmc.com.fmcsdk.util.Constant;
import sdk.webview.fmc.com.fmcsdk.util.CustomEdittext;
import sdk.webview.fmc.com.fmcsdk.util.GsonUtil;
import sdk.webview.fmc.com.fmcsdk.util.KLog;
import sdk.webview.fmc.com.fmcsdk.util.ToastUtils;

@SuppressLint("NotifyDataSetChanged")
public class WorkStartAdapter extends BaseQuickAdapter<GetDetailsBean.RecordDTO.PointsDTO.CheckListDTO, BaseViewHolder> {

    private ImageSelectAdapter imageSelectAdapter;
    private OnCameraPhotoListener onCameraPhotoListener;
    private boolean isShowNotInspected = true; // 是否只显示未检
    private OnWorkStartAdapterChildClickListener onWorkStartAdapterChildClickListener;

    private TextView tv_num;
    private GetDetailsBean getDetailsBean;


    public WorkStartAdapter(int layoutResId, OnCameraPhotoListener onCameraPhotoListener) {
        super(layoutResId);
        this.onCameraPhotoListener = onCameraPhotoListener;
    }

    public void setDetailBean(GetDetailsBean getDetailsBean) {
        this.getDetailsBean = getDetailsBean;
    }

    @Override
    public long getItemId(int position) {
        return Long.parseLong(getData().get(position).getId());
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(@NotNull BaseViewHolder holder, GetDetailsBean.RecordDTO.PointsDTO.CheckListDTO item) {
        TextView tv_standard = holder.getView(R.id.tv_standard);
        //.setText(R.id.tv_standard, item.getStandard())
        //  EventBus.getDefault().post(new StartEmptyEvent());
        String fullText = item.getStandard(); // 完整的文本内容
// 设置初始文本
        TextViewSpanUtil.toggleEllipsize(mContext,
                tv_standard, 2,
                fullText,
                mContext.getResources().getString(R.string.See_more),
                R.color.red, false);

        tv_standard.setOnClickListener(v -> onWorkStartAdapterChildClickListener.onStandardNameClick(fullText, holder.getAdapterPosition(), v));


        tv_num = holder.getView(R.id.tv_num);
        tv_num.setText(item.getPictureUrls().size() + "/9");
        holder.setGone(R.id.tv_bei_b, item.getMustFillRemark() != 0)
                .setGone(R.id.tv_camera_b, item.getMustTakePic() != 0);
        tv_num.setText(item.getPictureUrls().size() + "/9");
        if (item.getHasMeter() == 1) {
            //是设备水表
            holder.setGone(R.id.ll_shui, true)
                    .setGone(R.id.fl_item, false);

            if (item.getChecked() == 1) {  //已检测
                holder.setGone(R.id.iv_meter_status, true);
                if (item.getAbnormal() == 1) { //异常检测
                    holder.setImageResource(R.id.iv_meter_status, R.drawable.icon_detected_exception);
                } else {
                    holder.setImageResource(R.id.iv_meter_status, R.drawable.icon_checked_normal);
                }
            } else {
                holder.setGone(R.id.iv_meter_status, false);
            }


            if (isShowNotInspected) {//如果只显示未检
                if (item.getChecked() == 1) {
                    holder.getView(R.id.ll_shui).setVisibility(View.GONE);
                } else {
                    // holder.getView(R.id.ll_shui).setVisibility(View.VISIBLE);
                    if (item.isHasMasterShow()) {
                        holder.getView(R.id.ll_shui).setVisibility(View.VISIBLE);
                    } else {
                        holder.getView(R.id.ll_shui).setVisibility(View.GONE);
                    }
                }
            } else {
                //holder.getView(R.id.ll_shui).setVisibility(View.VISIBLE);
                if (item.isHasMasterShow()) {
                    holder.getView(R.id.ll_shui).setVisibility(View.VISIBLE);
                } else {
                    holder.getView(R.id.ll_shui).setVisibility(View.GONE);
                }
            }

            EditText etDetectionValue = holder.getView(R.id.et_detection_value);

            holder.getView(R.id.rl_enter).setOnClickListener(v -> {
                etDetectionValue.clearFocus();
                onWorkStartAdapterChildClickListener.onEnterWaterMeterClick(holder.getAdapterPosition());
            });

            etDetectionValue.setOnEditorActionListener((v, actionId, event) -> {
                // 判断是否是回车键，actionId 为 IME_ACTION_DONE
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    // 关闭软键盘（可选）
                    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                    etDetectionValue.clearFocus();

                    // 执行回车键按下时的操作
                    if (StringUtils.isEmptyString(etDetectionValue.getText().toString())) {
                        ToastUtils.showCustomToast(mContext, R.mipmap.icon_error, mContext.getResources().getString(R.string.Please_enter_the_value));
                    }
                    //onWorkStartAdapterChildClickListener.onInputWaterMeterValueClick(v, etDetectionValue.getText().toString(), holder.getAdapterPosition());
                    return true; // 返回 true 表示事件已经处理
                }
                return false; // 返回 false 表示事件没有处理，继续传播
            });

            etDetectionValue.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if (!hasFocus) {
                        // EditText失去焦点时执行的代码
                        // 例如：保存数据，执行检查等
                        if (!StringUtils.isEmptyString(etDetectionValue.getText().toString())) {
                            onWorkStartAdapterChildClickListener.onInputWaterMeterValueClick(v, etDetectionValue.getText().toString(), holder.getAdapterPosition());
                        }
                    }
                }
            });


            holder.setText(R.id.tv_water_meter, (holder.getAdapterPosition() + 1) + "." + item.getMeterName());
            etDetectionValue.setText(item.getMeterRead());
        } else {
            holder.setGone(R.id.ll_shui, false)
                    .setGone(R.id.fl_item, true);
            FrameLayout fl_item = holder.getView(R.id.fl_item);
            if (isShowNotInspected) {  //如果只显示未检
                if (item.getChecked() == 1) {
                    fl_item.setVisibility(View.GONE);
                } else {
                    fl_item.setVisibility(View.VISIBLE);
                }
                //holder.setVisible(R.id.iv_status, false);
                holder.setGone(R.id.iv_status, false);
            } else { // 要求全部显示
                fl_item.setVisibility(View.VISIBLE);
                if (item.getChecked() == 1) {
                    holder.setGone(R.id.iv_status, true);
                    if (item.getCheckResult().equals("N1")) {
                        holder.setImageResource(R.id.iv_status, R.drawable.icon_detected_exception);
                    } else if (item.getCheckResult().equals("Y1")) {
                        holder.setImageResource(R.id.iv_status, R.drawable.icon_checked_normal);
                    }

                } else {
                    holder.setGone(R.id.iv_status, false);
                }
            }

            CustomEdittext etRemake = holder.getView(R.id.et_remake);
            TextView tvRemakeFontCount = holder.getView(R.id.tv_remake_font_count);
            etRemake.setText(item.getRemark());
            etRemake.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                }

                @Override
                public void afterTextChanged(Editable editable) {
                    tvRemakeFontCount.setText(editable.length() + "/" + "100");
                    if (editable.length() > 100) {
                        editable.delete(100, editable.length());
                    }
                }
            });

            etRemake.setOnFocusChangeListener((view, b) -> {
                if (!b) {
                    String newText = StringUtils.isEmptyString(etRemake.getText().toString()) ? "" : etRemake.getText().toString();
                    int position = holder.getAdapterPosition();
                    if (position != RecyclerView.NO_POSITION) {
                        getData().get(position).setRemark(newText);
                    }

                    if (item.getMustFillRemark() != 0) {
                        if (StringUtils.isEmptyString(item.getRemark())) {
                            //备注必填 但是没填
                            return;
                        }
                    }

                    if (item.getMustTakePic() != 0) {
                        if (item.getPictureUrls().isEmpty()) {
                            //拍照必填 但是没填
                            return;
                        }
                    }

                    if (StringUtils.isNotEmptyString(item.getCheckResult())) {  //证明当前已经选择了正常 或者异常
                        item.setChecked(1);
                        fl_item.setVisibility(View.GONE);
                    } else {
                        fl_item.setVisibility(View.VISIBLE);
                    }
                }
            });

            etRemake.setOnEditorActionListener((textView, i, keyEvent) -> {
                if (i == EditorInfo.IME_ACTION_DONE) {
                    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(etRemake.getWindowToken(), 0);
                    etRemake.clearFocus();

                    return true;
                }
                return false;
            });

            holder.setText(R.id.tv_title, (holder.getAdapterPosition() + 1) + "." + item.getTitle());

            if (item.getAbnormal() == 1) {
                holder.getView(R.id.ll_pai).setVisibility(View.VISIBLE);
                holder.setGone(R.id.tv_pai_xing,false);
            } else {
                GetDetailsBean.RecordDTO.ExceptionReportDTO exceptionReport = getDetailsBean.getRecord().getExceptionReport();
                if (null != exceptionReport) {
                    String exceptionReportValue = exceptionReport.getExceptionReport();
                    if (StringUtils.isNotEmptyString(exceptionReportValue)) {
                        KLog.e(exceptionReportValue);
                        if (TextUtils.equals(exceptionReportValue,"3") || TextUtils.equals(exceptionReportValue,"4") ||TextUtils.equals(exceptionReportValue,"6")) {
                            holder.setGone(R.id.tv_pai_xing,true);
                            KLog.e("222222");
                        } else {
                            holder.getView(R.id.tv_send_order_required).setVisibility(View.GONE);
                            KLog.e("222222");
                            holder.setGone(R.id.tv_pai_xing,false);
                        }
                    } else {
                        holder.getView(R.id.tv_send_order_required).setVisibility(View.GONE);
                        KLog.e("222222");
                    }
                } else {
                    holder.getView(R.id.tv_send_order_required).setVisibility(View.GONE);
                    KLog.e("222222");
                }
            }
            if(item.getChecked()!=1){
                if(TextUtils.equals(item.getCheckResult(),"N1")){
                    holder.getView(R.id.ll_pai).setVisibility(View.VISIBLE);
                }else {
                    holder.getView(R.id.ll_pai).setVisibility(View.GONE);
                }
            }

            holder.getView(R.id.ll_paipai).setOnClickListener(v -> {
                if (onWorkStartAdapterChildClickListener != null) {
                    onWorkStartAdapterChildClickListener.onErrorClick(v, holder.getAdapterPosition());
                }
            });
            String checkResultType = item.getCheckResultType();
            // List<DDTypeBean.RecordsBean> recordsBeans = FMCApplication.typeMap.get(checkResultType);
            String json = CacheHelper.getInstance().getMapJson(checkResultType);
            if (!TextUtils.isEmpty(json)) {
                List<DDTypeBean.RecordsBean> records1111 = GsonUtil.jsonToList(json, DDTypeBean.RecordsBean.class);
                if (null != records1111) {
                    LinearLayout llStateContent = holder.getView(R.id.ll_state_content);
                    LinearLayout ll11 = holder.getView(R.id.ll_111);
                    LinearLayout ll22 = holder.getView(R.id.ll_222);
                    LinearLayout ll33 = holder.getView(R.id.ll_333);
                    createStateUi(records1111, llStateContent, item, holder, ll11, ll22, ll33);
                }
            }

            List<ImageSelectBean> imageList = new ArrayList<>();
            String baseUrl = PreferenceManager.getDefaultSharedPreferences(mContext).getString(Constant.BASE_ADDRESS_URL, "");
            for (GetDetailsBean.RecordDTO.PointsDTO.CheckListDTO.PictureUrlsDTO pictureUrl : item.getPictureUrls()) {
                String picUrl = pictureUrl.getUrl();
                if (!pictureUrl.getUrl().contains("com.fmob.client.app.gmy/files/fmc/gmy/h5image")) {
                    picUrl = baseUrl + pictureUrl.getUrl();
                }
                imageList.add(new ImageSelectBean(picUrl, 1));
            }

            item.setImageList(imageList);

            RecyclerView rv_img = holder.getView(R.id.rv_img);
            rv_img.setLayoutManager(new GridLayoutManager(mContext, 5));
            imageSelectAdapter = new ImageSelectAdapter(item.getImageList());
            rv_img.setAdapter(imageSelectAdapter);

            if (isHaveImage(item.getImageList())) {
                item.setCamera(true);
            }

            holder.setGone(R.id.ll_camera, item.isCamera());
            holder.setGone(R.id.ll_remake, item.isBei());


            holder.getView(R.id.ll_cam).setOnClickListener(v -> {
                if (onWorkStartAdapterChildClickListener != null) {
                    onWorkStartAdapterChildClickListener.onPictureClick(holder.getAdapterPosition());
                }
            });


            holder.getView(R.id.ll_reamrk).setOnClickListener(v -> {
                if (onWorkStartAdapterChildClickListener != null) {
                    onWorkStartAdapterChildClickListener.onRemakeClick(holder.getAdapterPosition());
                }
            });

            holder.getView(R.id.ll_send_orders).setOnClickListener(v -> {
                if (onWorkStartAdapterChildClickListener != null) {
                    onWorkStartAdapterChildClickListener.onErrorClick(v, holder.getAdapterPosition());
                }
            });

            imageSelectAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    if (view.getId() == R.id.ll_add_pic) {
                        onCameraPhotoListener.cameraPhotoListener(holder.getAdapterPosition(), item.getId());
                    } else if (view.getId() == R.id.iv_view) {
                        onCameraPhotoListener.photoShowListener(position, item.getImageList());

                    }
                }
            });
            imageSelectAdapter.setOnItemChildLongClickListener(new OnItemChildLongClickListener() {
                @Override
                public boolean onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {
                    if (onWorkStartAdapterChildClickListener != null) {
                        ImageSelectBean imageSelectBean = (ImageSelectBean) adapter.getData().get(position);
                        boolean isHave0 = false;
                        for (int i = 0; i < adapter.getData().size(); i++) {
                            ImageSelectBean listBean = (ImageSelectBean) adapter.getData().get(i);
                            if (listBean.getType() == 0) {
                                isHave0 = true;
                            }
                        }
                        if (imageSelectBean.getType() != 0) {
                            onWorkStartAdapterChildClickListener.onPictureRemoveClick(holder.getAdapterPosition(), isHave0 ? position - 1 : position);
                        }
                    }
                    return true;
                }
            });

        }
    }


    public void setOnWorkStartAdapterChildClickListener(OnWorkStartAdapterChildClickListener onWorkStartAdapterChildClickListener) {
        this.onWorkStartAdapterChildClickListener = onWorkStartAdapterChildClickListener;
    }


    public void setShowBoole(boolean isShowNotInspected) {
        this.isShowNotInspected = isShowNotInspected;
        this.notifyDataSetChanged();
    }

    public void addImageList(String imageUrl, int position) {
        List<ImageSelectBean> beanImgList = getData().get(position).getImageList();
        beanImgList.add(new ImageSelectBean(imageUrl, 1));
        if (beanImgList.size() > 9) {
            removeAdd(beanImgList);
        }
        imageSelectAdapter.setNewData(beanImgList);
        notifyDataSetChanged();
    }

    public void addVideoList(String videoUrl, int position) {
        List<ImageSelectBean> beanImgList = getData().get(position).getImageList();
        beanImgList.add(new ImageSelectBean(videoUrl, 2));
        if (beanImgList.size() > 9) {
            removeAdd(beanImgList);
        }
        imageSelectAdapter.setNewData(beanImgList);
        notifyDataSetChanged();
        imageSelectAdapter.notifyDataSetChanged();
    }

    private void removeAdd(List<ImageSelectBean> imageList) {
        for (int i = 0; i < imageList.size(); i++) {
            if (imageList.get(i).getType() == 0) {
                imageList.remove(i);
            }
        }
    }

    private void createStateUi(List<DDTypeBean.RecordsBean> recordsBeans, LinearLayout llStateContent, GetDetailsBean.RecordDTO.PointsDTO.CheckListDTO item, BaseViewHolder holder, LinearLayout ll11, LinearLayout ll22, LinearLayout ll33) {
        //llStateContent.removeAllViews();
        ll11.removeAllViews();
        ll22.removeAllViews();
        ll33.removeAllViews();
        for (int i = 0; i < recordsBeans.size(); i++) {
            LinearLayout rowLayout = new LinearLayout(mContext);
            // 设置 LinearLayout 的布局参数（宽度为自适应内容，高度为自适应内容）
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT,// 宽度沾满
                    LinearLayout.LayoutParams.WRAP_CONTENT   // 高度自适应内容
            );
            rowLayout.setLayoutParams(layoutParams);
            // 设置 LinearLayout 的方向（可以选择水平或垂直）
            rowLayout.setOrientation(LinearLayout.HORIZONTAL);

            boolean isThree;
            if (recordsBeans.size() >= 3) {
                isThree = true;
            } else {
                isThree = false;
            }
            // 每行最多放三个元素
            for (int j = 0; j < 3; j++) {
                // 计算当前显示的数据项在 recordsBeans 中的索引
                int currentIndex = i * 3 + j;
                if (currentIndex >= recordsBeans.size()) break; // 如果索引超过集合大小，停止添加

                // 创建每条数据的 LinearLayout
                LinearLayout itemLayout = new LinearLayout(mContext);
                itemLayout.setOrientation(LinearLayout.HORIZONTAL);  // 设置垂直方向排列
                itemLayout.setLayoutParams(new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT, // 宽度为 0
                        LinearLayout.LayoutParams.WRAP_CONTENT// 权重为 1，等比例分配空间
                ));
                DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
                int width = displayMetrics.widthPixels;
//                if (isThree) {
//                    itemLayout.setMinimumWidth(width * 285 / 1080);
//                } else {
//                    itemLayout.setMinimumWidth(width * 440 / 1080);
//                }
                // 创建 ImageView 和 TextView
                ImageView imageView = new ImageView(mContext);
                TextView textView = new TextView(mContext);

                // 设置 ImageView 和 TextView 的 UI 样式
                if (null != item.getCheckResult() && item.getCheckResult().equals(recordsBeans.get(currentIndex).getCode())) {
                    imageView.setImageResource(R.mipmap.icon_check_red);
                } else {
                    imageView.setImageResource(R.mipmap.icon_select_no);
                }
                StringBuffer spaceString = new StringBuffer();
                textView.setText(recordsBeans.get(currentIndex).getDescription() + spaceString);
                // 使用 recordsBeans 中的文本数据
                textView.setTextColor(Color.parseColor("#393A42"));  // 设置字体颜色为 #393A42
                textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); // 设置字体大小为 18sp

                // 设置 LayoutParams（宽度为 0，以权重分配空间）
                LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT, // 宽度为 MATCH_PARENT
                        LinearLayout.LayoutParams.WRAP_CONTENT  // 高度自适应
                );
                LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT,  // 宽度为 MATCH_PARENT
                        LinearLayout.LayoutParams.WRAP_CONTENT  // 高度自适应
                );

                int leftMargin = (int) (5 * getDisplayMetrics(mContext).density);
                textParams.setMargins(leftMargin, 0, 0, 0);

                imageView.setLayoutParams(imageParams);
                textView.setLayoutParams(textParams);

                // 将 ImageView 和 TextView 添加到每条数据的 LinearLayout
                itemLayout.addView(imageView);
                itemLayout.addView(textView);
                itemLayout.setGravity(Gravity.CENTER_VERTICAL);


                // 为 itemLayout 设置边距
                if (j == 0) {
                    // 最左边的元素
                    //itemLayout.setPadding(0, 0, 0, 0);  // 设置左边距为 7dp
                    itemLayout.setHorizontalGravity(Gravity.START);
                } else if (j == 1) {
                    // 中间的元素
                    //itemLayout.setPadding(15, 0, 15, 0); // 设置左右边距为 15dp
                    if (j == recordsBeans.size() - 1) {
                        itemLayout.setHorizontalGravity(Gravity.START);
                    } else {
                        itemLayout.setHorizontalGravity(Gravity.START);
                    }

                } else {
                    // 最右边的元素
                    //itemLayout.setPadding(0, 0, 0, 0);  // 设置右边距为 7dp
                    itemLayout.setHorizontalGravity(Gravity.START);
                }
                // 将 itemLayout 添加到当前行的 rowLayout
                if (isThree) {
                    switch (j) {
                        case 0:
                            ll11.addView(itemLayout);
                            break;
                        case 1:
                            ll22.addView(itemLayout);
                            break;
                        case 2:
                            ll33.addView(itemLayout);
                            break;
                    }
                } else {
                    switch (j) {
                        case 0:
                            ll11.addView(itemLayout);
                            break;
                        case 1:
                            ll33.addView(itemLayout);
                            break;
                    }
                }

                //  rowLayout.addView(itemLayout);

                String code = recordsBeans.get(currentIndex).getCode();
                itemLayout.setOnClickListener(v -> {
                    if (code.equals("Y1") || code.equals("Y2")) {
                        if (onWorkStartAdapterChildClickListener != null) {
                            onWorkStartAdapterChildClickListener.onNormalClick(holder.getAdapterPosition(), code);
                        }
                    } else if (code.equals("N1")) {
                        if (onWorkStartAdapterChildClickListener != null) {
                            onWorkStartAdapterChildClickListener.onErrorClick(v, holder.getAdapterPosition());
                        }
                    }
                });
            }

            //  llStateContent.addView(rowLayout);


        }
    }


    public interface OnWorkStartAdapterChildClickListener {
        void onRemakeClick(int position);

        void onPictureClick(int position);

        void onNormalClick(int position, String checkResult);

        void onErrorClick(View view, int position);

        void onPictureRemoveClick(int groupPosition, int position);

        void onEnterWaterMeterClick(int position);

        void onInputWaterMeterValueClick(View view, String value, int position);

        void onStandardNameClick(String value, int position, View v);
    }


    private boolean isHaveImage(List<ImageSelectBean> list) {
        boolean isHave = false;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getType() != 0) {
                isHave = true;
            }
        }
        return isHave;
    }


}
